#! /bin/sh

if [ $# -lt 1 ]; then
    echo "Sintaxe: `basename $0` list-arqs"
    exit 10
fi

for full_file_name in "$@"; do

    echo -n "$full_file_name "

    # file exists?
    if [ ! -f "$full_file_name" ]; then
        echo " nao encontrado!"
        exit 20
    fi

    new_file_name=$PWD/`basename $full_file_name`
    cp -f $full_file_name $new_file_name 2> /dev/null


    # was a frame already added?
    echo "$new_file_name" | grep M_ 2> /dev/null > /dev/null
    if [ $? -eq 1 ]; then
        echo " nao possui moldura!"
    else
        w_px=`identify -format "%w" $new_file_name`
        h_px=`identify -format "%h" $new_file_name`

        font_size=$((w_px / 10 ))

        # write my name
        convert $new_file_name -gravity SouthEast  -font Courier -pointsize 18 -annotate 270x270+50+200 'Rodrigo Canellas' $new_file_name

        echo " assinado"
    fi 



done

